import java.util.Stack;

public class MinStack {
    private Stack<Integer> s;//普通栈
    private Stack<Integer> minStack;//当前栈的最小值

    public MinStack() {
        s = new Stack<>();
        minStack = new Stack<>();
    }

    //入栈
    public void push(int val) {
        s.push(val);//普通栈必须放
        if (minStack.empty()){
            //直接也存在最小栈一份
            minStack.push(val);
        }else{
            int peekV = minStack.peek();
            if (val <= peekV){
                minStack.push(val);
            }
        }
    }

    //出栈
    public void pop() {
        int popV = s.pop();
        int peekVMins = minStack.peek();
        if (popV == peekVMins){
            minStack.pop();
        }
    }

    public int top() {
        return s.peek();
    }

    public int getMin() {
        return minStack.peek();
    }
}
